package com.taplinker.client.im.rpc;

import java.util.List;

import com.taplinker.client.AppConfigFactory;
import com.taplinker.client.im.domain.ImDataCenter;
import com.taplinker.client.im.rpc.body.Cmd013Rep;
import com.taplinker.core.rpc.Result;
import com.taplinker.core.util.json.JsonUtil;

public class Cmd013 extends SimpleSocketCommand<Object> {

	public Cmd013() {
		body = new Object();
	}
	
	@Override
	public void yes(Result result) {
		super.yes(result);
		
		List<Cmd013Rep> list = JsonUtil .jsonToList(((IMMessageResponse) result.object).getMessage().getBody(), Cmd013Rep.class);
		Cmd013Rep cmd = null;
		for(Cmd013Rep rep : list) {
			if(rep.getUserId() == AppConfigFactory.getInstance().getUserInfo().getUserid()){
				cmd = rep;
			}
		}
		if(cmd != null) {
			list.remove(cmd);
		}
		
		ImDataCenter.getInstance().addCustomerList(list);
		ImDataCenter.getInstance().noticeListener(ImDataCenter.CUSTOMER_REFRESH);
	}
	
	@Override
	protected String getCommand() {
		return "013";
	}
}
